package com.zyl.longpicturebackend.model.enums;

import cn.hutool.core.util.ObjectUtil;
import lombok.Getter;

@Getter
public enum UserRoleEnum {

    ADMIN("管理员", "admin"), USER("普通用户", "user");

    private final String roleName;
    private final String roleValue;

    UserRoleEnum(String roleName, String roleValue) {
        this.roleName = roleName;
        this.roleValue = roleValue;
    }


    public static UserRoleEnum getUserRoleEnumByRoleName(String roleName) {
        if (ObjectUtil.isEmpty(roleName)) {
            return null;
        }
        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            if (userRoleEnum.roleName.equals(roleName)) {
                return userRoleEnum;
            }
        }
        return null;
    }

    public static UserRoleEnum getUserRoleEnumByRoleValue(String roleValue) {
        if (ObjectUtil.isEmpty(roleValue)) {
            return null;
        }

        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            if (userRoleEnum.roleValue.equals(roleValue)) {
                return userRoleEnum;
            }
        }

        return null;
    }


}
